Allan Alexander Mackenzie, Royal Engineers