There is an “event” called the “choice-of-arms”, which is conducted a month before the passing out parade every term at IMA and OTA.
The total no of vacancies available will be equal to the no of cadets passing out. The vacancies will be divided amongst all the arms and services. This division is done based on the strength of each arm/service and a host of other factors which are too complicated to explain here.
Within each arm, for example infantry, the vacancies will be further subdivided amongst the various Battalions. All battalions do not get vacancies every time, it depends on whether the battalion is in field, whether the battalion is facing a shortage of officers etc.
During the choice of arms, the cadets write down their preferred three choices (it’s not that simple a procedure, but that’s enough for this answer). Taking into account a host of factors primarily merit and lady luck, the cadet may or may not get his choice (they generally do).
While giving the choice, you cannot choose the exact battalion you want, just the arm or service. The battalion will be allocated to you by the powers above.
Anyone having a parental claim or is in the top five in merit in the entire course will get the Battalion/arm/service of their choice.