There are a few areas that need to be considered: authority and army, opponents, strategy and reinforcements, and personal qualities.
Authority and army
Alexander, although he became king at just 19, had already seen battle (playing a crucial role in the Battle of Chaeronea when he was 17). He was battle-hardened, king and commander-in-chief. Whilst the Macedonian king wasn’t fawned over like the Persian Great King, he was clearly in charge (like a Prime Minister rather than a President). His army consisted of Macedonians and Greeks, both of whom were Hellenistic and quite similar in terms of fighting style. As well as the throne, he inherited the best army in the world, brilliantly developed and trained his excellent father, Philip.
Hannibal also grew up fighting, first for his father and then Hasdrubal the Handsome, his brother-in-law (both in Iberia). Then he assumed command of Carthage’s Iberian forces. He did not have particular political authority, and had a mixed army of veterans from numerous corners of the world all speaking different languages and with different weapons and armour.
In terms of authority, Alexander had a clear advantage. Hannibal had a very good army, although here too I’d give Alexander a slight edge (his elite soldiers were so good they were still in high demand decades after his death).
Alexander faced three sets of opponents. Firstly, the Greeks. They’d been smashed by his father and sought to escape the rule of Macedon when Alexander took the throne. They were cunning opponents and almost ended his career before it got going, but he overcame them fairly quickly. Secondly, he faced the massed armies of the Persian Empire. Although the horsemen were brave and talented, the foot soldiers were less so and no match for the high calibre of the Macedonian army. Furthermore, Alexander was tactically brilliant, and (by making the Great King flee twice) made hordes of Persians flee at Arbela and Issus. I’d say the Indians, who were pretty damned clever and had lots of war elephants, were his greatest opponents (particularly Porus).
Hannibal did fight the Iberians, but that was mostly under the command of others. Whilst he was in charge he only really fought the Romans. During this time he inflicted numerous defeats upon numerically superior forces, including one of the greatest ambushes in history at Lake Trasimene and the most crushingly brilliant victory in history (arguably) at Cannae. He did lose to Scipio at Zama, however. After the war ended he continued, after a brief pause to lead the city, to fight the Romans, on behalf of Eastern despots.
Alexander had the easier task, I feel. Yes, the Persians had huge manpower, but the armies crumbled like rotted wood when Darius fled and Alexander had the finest soldiers in the world. Hannibal, meanwhile, faced Rome at the zenith of its patriotic determination and fervour. Even after the slaughter of Cannae the city did not contemplate surrender, and although initially they were tactically naïve, later the likes of Marcellus, Nero and Scipio learnt the lessons Hannibal had taught them to good effect.
Strategy and reinforcements
Alexander’s strategy was simple. March at Persia, accept surrendering cities kindly and slaughter everyone who didn’t recognise him as king. However, the detail of this was intelligent. He did not leave strong cities at his back (unless they were besieged by his lieutenants), and if a city did rebel or refuse to kneel he was pretty ruthless, encouraging the others to fling their doors open instead of having them rammed to splinters. In the open field he was victorious, in siegecraft he was relentless and he made scarcely a mistake when it came to invading Persia. He did, however, bugger up the end of his reign by unnecessarily marching through the Gedrosian desert. Reinforcements came as and when he needed them and he also recruited heavily from Persian soldiers who had served Darius previously, much to the irritation of his fellow Macedonians.
Hannibal took the heroic/slightly mental approach of marching an army, including elephants, over the Alps. In winter. His strategy relied upon gaining local support in Italy itself, and he achieved this to a certain extent, but it was never sufficient to deliver him ultimate victory. He was hamstrung by the fact that Carthage rarely sent him reinforcements and, although rebellious Gauls did offer him some more men, the army of his brother (also called Hasdrubal) that crossed the Alps was immediately slaughtered by the consul Nero.
Alexander did better when it comes to strategy, I think. He made a damned silly error at the end, but he succeeded in his overall objective of smashing Persia. The ample reinforcements he received did help considerably. Hannibal’s strategy was difficult, but his objective was harder. Fighting in Italy was the right thing to do, but manpower became an issue in the later years and he was sadly unable to be reunited with his brother.
Alexander was a great leader, and not just in a tactical or strategic sense. He delegated well, he was merciful to cities that surrendered and he was always ready to lead the charge (indeed, he very nearly got killed when two scaling ladders broke and he was shot in the lung, facing numerous opponents and had just two bodyguards still with him). However, he did have little flaws, like murdering one of his best friends (Cleitus, who had saved his life at the Granicus) whilst drunk. His ambition enabled him to achieve great feats, but ultimately his army forced him to turn back from India, having grown wear of being away from home for a decade. It is notable that he treated the wives and children of Darius well, and was merciless to those Persians who had slain the Great King.
Hannibal’s personality is harder to judge because his history is written by the opposing side. Despite having a mixed force with very few actual Carthaginians in it, he suffered from desertion just once (a few hundred Numidian cavalry after years in Italy) during 10 years in enemy territory. He was rather more civilised than the Romans when it came to honouring the dead, searching for Flaminius’ body for hours after the ambush at Lake Trasimene so that he might give it a decent ceremony. By contrast, the consul Nero, who slew his brother Hasdrubal, cut off the head and had it hurled into Hannibal’s camp.
Hard to assess. I think it’s reasonable to say that Alexander exceeded Hannibal in vices (Hannibal never got in a drunken fight and killed a close friend), but that Alexander may have been a better leader of men.
Overall, I think Hannibal’s achievements are the greater. He fought for longer against a more difficult foe, usually outnumbered, permanently (after the Alps) in enemy territory, rarely receiving reinforcements and lacking total authority over the Carthaginian state. That’s not to belittle Alexander in any way. He never lost, and deservedly became a legend in his own lifetime. Would he have done so well in Hannibal’s position, or vice versa? If he had lived and then gone west from Macedon I daresay Rome would have become yet another conquest of his.