Note: The Guard and Reserves also guarantee the duty station because they are recruiting to fill specific, open slots in specific Guard & Reserve units.
For the rest of the services (and the Army, if you don't have a guaranteed first duty station in your enlistment contract), first duty station selection is made (in either basic training or technical school), based upon your preferences, and the "needs of the service."
In most cases, you fill out a form, known as a "dream sheet" to list your assignment preferences. While the services will consider your preferences, the overriding deciding factor is where the military needs you the most. If that coincides with one of your preferences, great. If not, you'll be assigned to where the service wants you.
For some Navy Jobs, your assignment can also be based on your class-standing in "A-School." In other words, the person at the "top of the class," would have a better chance of receiving the assignment he/she wants than the person at the "bottom of the class."
For more detailed information, see Part 10 of What the Recruiter Never Told You.

