This is an area you can really play around with. Anywhere from not dry hopping at all, to adding to the fermenter toward the end of fermentation, to waiting till its done and pitching them, all the way to some guys who add them to the keg and dont remove them until the keg is empty. Its all personal preference and depending on what you are trying to achieve. Ive had good luck with tossing them in the fermenter once I hit terminal gravity, letting them soak and settle to the bottom for a few days, then just racking the beer. Anywhere from 3-10 days gives decent results. Ive also pitched them into the keg, in a hop sack, and left them in for the duration. No ill effects unless the keg lives for a really long time.