Obviously, you have to observe the overall contour of the melody to assure you don't run out of room. That said, I find it very helpful to relate the melody to an appropriate chord shape, scale, series of scales, arpeggio(s), chromatic lick, or any combination thereof. This not only helps me find appropriate positions, but it has to extra added benefit of making memorization and transposition of the melody (if desired) relatively easy once I've worked the positions out in this manner. It's just a matter of "seeing" the the scale, chord, or arpeggio shapes, etc. in a different position on the fretboard.
The other real key benefit of this approach is that you instantly have a road map for how to play over the changes. Maybe not the only way that you would want to approach the changes, but it's one way, you have in your back pocket that will keep you close to the melody, if that's what your looking to do. Not sure if I've been totally clear in explaning this; but I hope it helps.