There are four measures (to be applied in that order), viz - Sama (peacemaking), Dana (buying off with gifts), Bheda (dissension), and finally Danda (punishment/force or war), for the king to apply on his foes.
First, he should try the three measures, either separately or jointly, apart from war, because war is always disastrous and moreover the result is hard to predict beforehand. But if/when those measures fail to bear any fruit, he can resort to war.
The Manu Smriti states war should be avoided till the point when it is impossible to do so.
7.198. He should (however) try to conquer his foes by conciliation, by (well-applied) gifts, and by creating dissension, used either
separately or conjointly, never by fighting, (if it can be avoided.)
7.199. For when two (princes) fight, victory and defeat in the battle are, as experience teaches, uncertain; let him therefore avoid an
7.200. (But) if even those three before-mentioned expedients fail, then let him, duly exerting himself, fight in such a manner that he
may completely conquer his enemies.
The whole chapter 7 of the text is talking about the duties of the king and among which some verses are dedicated to war.
Few more relevant verses are as follows:
7.164. War is declared to be of two kinds, (viz.) that which is undertaken in season or out of season, by oneself and for one’s own
purposes, and (that waged to avenge) an injury done to a friend.
7.169. When (the king) knows (that) at some future time his superiority (is) certain, and (that) at the time present (he will
suffer) little injury, then let him have recourse to peaceful
7.170. But when he thinks all his subjects to be exceedingly contented, and (that he) himself (is) most exalted (in power), then
let him make war.
7.174. But when he is very easily assailable by the forces of the enemy, then let him quickly seek refuge with a righteous, powerful
7.176. When, even in that (condition), he sees (that) evil is caused by (such) protection, let him without hesitation have recourse to war.
About Sama, Dana, Bheda, Danda :
We find references to these four measures in various scriptures.
For example mentioned in the following passage from Devi Bhagavatam Book 1, Chapter 7:
1-26. Sûta said :-- Seeing the two Dânavas very powerful, Brahmâ,
the knower of all the S’âstras, thought of the means Sâma, Dâna,
Bheda, Danda (conciliation, gifts, bribe, or sowing dissensions and
war or punishment); which of these four he should apply. He thought
thus :-- “I do not know their strength and it is not advisable to
enter into war without knowing their strength. Again if I offer
praises to them puffed up with pride, it will be simply displaying my
own weakness; and when they will come to know this, only one of them
will be sufficient to kill me and this they will do certainly. To
offer bribes is not also advisable; and how can I sow dissensions
and, again, in the same Purana's Book 5, Chapter 9:
“O Best of ministers! O Hero! Under my command, go there with all the
forces and use the means, conciliation, etc., and bring that woman,
having a beautiful face (like the Moon), to me. If that Lady do not
come even when the three policies, Sâma (conciliation), Dâna (making
gifts), and Bheda (sowing dissensions in an enemy's party and thus
winning him over to one's side, one of the four Upâyas or means of
success against an enemy) are adopted by you, then apply the last
resort Danda, (or war) in such a way that Her life be not destroyed
and bring that beautiful woman to me.
So, for the king it will be wrong to straightaway engage in a war, without trying the other three measures first.