Ibn Ishaq (may Allah have mercy on him) said: The Messenger of Allah (peace and blessings be upon him) intended to fight. He (peace and blessings be upon him) began jihad against the enemies whom Allah Almighty had commanded him (to fight), and Allah Almighty had commanded him to fight the nearest polytheists first.
Imam al-Shafi'i (may Allah have mercy on him) said: If the condition of the enemy differs, that is, some of them cause more harm than others or are more feared than others, then the commander will fight first the enemy from whom there is more danger, even if his land is farther away; and this will be in a case of necessity.
He said: When the Prophet (peace and blessings be upon him) received news that al-Harith bin Abi Dirar was gathering an army, he (peace and blessings be upon him) launched a night attack on him, while around him (peace and blessings be upon him) there were enemies who were nearer than al-Harith bin Abi Dirar.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب السير / 17881