How can an ATC choose the right flight level and heading for airplanes?
During the enroute portion of the flight at cruising altitude, pilots will have filed a cruise altitude and route based on airplane performance and weather. ATC will not need to change this unless the pilots ask to deviate or there would be a separation issue. Separation will depend on the local regulations and type of airspace and aircraft involved. For airliners this is usually 3 miles laterally or 1,000 feet vertically. 

Pilots may request deviations from their filed route due to weather or other reasons. ATC will look at other traffic in the area and determine what changes can safely be made. ATC may also need to give altitude changes to keep them clear of other traffic. If two planes are converging at the same altitude, at least one of them would need to climb or descend.

When arriving at the destination, many airports have stardard terminal arrival (STAR) procedures that pilots use in their route and may give route and altitude instructions. ATC will also have standard procedures for routes and altitudes that will allow arriving aircraft to descend without interfering with departures or other airspace in the area.