You won't need a transit visa as long as your connecting flight is from the same airport and is within say 5 to 12 hours. However, if you need to leave one airport to another, you will need a transit visa to travel to next destination. Now, let's not get confused with different terminals at the same airport, if your flight lands at terminal 1 and next flight departs from terminal 4 (but both terminal at the same airport), you do not need a transit visa. Should you need a transit visa, ideally you should apply ahead of your journey, however, obtaining a transit visa at POE is also not that difficult subject to possessing a valid Canadian Visa and connecting flight ticket. But it depends on individual individual, travel history etc. I never had problem obtaining transit visa at POE.