Missed the OCS part and was vague cuz I didn't know how enlisted detailing works.
In off-crew of prototype you fill out your preferences. You have to put everything. The detailer gets a 'green' detail if he puts you 1-3 and a 'yellow' if 4-10.
From what the detailing office has told us after PNEO (and I'm skeptical that it was 100% true), they go by class rank and what you list. So if you're #1 you'll end up at your #1 choice, if billets are available there. My class graduated with no billets detailed to San Diego because none were available, for example. If you're #2 and #1 filled up all the billets at that port, you get your #2 choice; otherwise, you get #1. On and on it goes down the list. But if there is more than 1 billet available on a ship, they will try to even out the talent, hence 'quality spread.' What can also screw you there is that if a boat loses a JO with a very high tech rating and you do well, you could be sent to replace him even if you're #1 in the class and it's your 4-10th choice. Also, since there is only 'green' and 'yellow' as far as the detailer is concerned, he only cares about putting you in one of those categories.
Realistically, there's very little you can do to game the system or increase your chances of one port over another, unless you list the ports by the # of submarines present at that port. There is a space to write any additional circumstances but they only care about spouses, not gfs.
Just study hard and do the best you can do and the Navy will take you where it wants to take you.
As for shore duty billets, the majority of them tend to be subschool instructor billets at the sub bases or prototype instructor, with a few staff jobs thrown in.