Put the gammon in a large deep pan and cover with cold water. Add the bay leaf, carrot, studded onion and a few peppercorns and bring to the boil. Use a slotted spoon to skim off any scum from the surface, then reduce the heat and simmer, uncovered, for 1 hour, topping up the water level as needed. Remove the gammon, discard the stock and set aside for 30 minutes to cool.
Meanwhile, make the glaze. Put the apricot jam, 1 tablespoon of the apple juice, 1 tablespoon of the vinegar and the ginger in a small pan and heat gently, whisking all the time, until the apricot jam has dissolved. Bring to the boil then simmer for 2-3 minutes until syrupy.
Preheat the oven to 190°C, fan 170°C, gas 5. Cut away and discard most of the fat from the gammon, leaving just a thin layer of the fat. Score the fat in a diamond pattern and transfer the joint to a large deep roasting tin. Add the shallots and pour in 250ml of the remaining apple juice. Brush the glaze all over the scored fat and sprinkle over the demerara sugar, pressing down gently with the back of a spoon. Roast for 1 hour, basting every so often with the pan juices, until the glaze is golden and caramelised and the shallots are tender.
Remove the gammon from the roasting tin, cover and keep warm while you make the gravy. Put the roasting tin (with the shallots and pan juices) on the hob over a medium heat. Sprinkle over the flour and cook for 1 minute, scraping any sediment from the bottom of the tin. Gradually stir in the rest of the apple juice and the remaining vinegar and bring to the boil, stirring all the time. Reduce the heat and simmer for 3-4 minutes until thickened. Season to taste with freshly ground black pepper and serve with the slices of the warm gammon.