What do you mean by 'nearest'?
Do you mean nearest in alphabetical terms, whereby Manchester is closer to London than Gatwick, or nearest in geographic terms?
The former solution is trivial, but not very helpful.
The latter requires that you have GPS coordinates for each postcode, but assuming you have access to this information, would be fairly trivial to code as well. The distance between two points in a Cartesian plane is very easy to calculate, to the extent that you could possibly do a real-time calculation from one postcode to all other postcodes in the UK without any significant lag. More efficient methods exist, of course, examples of which can no doubt be found through Google.