To send a piece of mail to a ship, you send it to a Fleet Post Office, listed as the city and state.
For example, if the ship is stationed in the pacific fleet (AP- armed forces pacific), you’d send it to:
Jane Q Sailor USS Whatever FPO AP (the unit zip code)
And the mail would be forwarded to the ship anywhere in the world to meet the ship with supplies. I don’t know all the codes, but they’re all similarly formatted.