I did this with the iPhone 5 (except I was switching from AT&T to Verizon).
When the phone arrived and I activated it, my phone number was automatically ported to Verizon and the phone worked. All I needed to do at that point was call up AT&T and terminate my service with them.