The gearbox on my 2.7TD failed quite spectacularly a week before I was due to drive it to Spain (a loud bang, then no drive at all).
Didn't have time to source a used box so I took it to a gearbox specialist, a bearing had broken up and caused a lot of damage. They overhauled the box, replaced the (damaged) clutch and overhauled the transfer box while they were at it.
With recovery to my local garage, then again to the specialist, total cost was £1900 (I only paid £1500 for the car).
I got it back the day before we were due to leave for Spain so it was completely untested - however it covered the 800 miles or so from Bristol to Plymouth then Santander to Malaga without a murmur, and since then has covered about 35,000 miles on Spanish roads with no further gearbox issues, so if you can locate a good gearbox rebuilder you will end up with hopefully a "good-as-new" gearbox, whereas if you go for a second hand one you have no way of knowing it's condition until it's fitted and running.
IMO a rebuild is the safest option.