Basically for a finished soda, there's going to be a lot of foam. It's even worse if there's a juice or some sort of pulp or particulate in your soda. The sugar concentration makes it harder for CO2 to stay in solution, and the pulp and stuff makes great nucleation points for the gas to escape to.
My preferred method is to carbonate water in the keg, then portion flavored syrup into bottles. Slowly fill the bottles with carbonated water under pressure, cap, then shake to mix. This way it's easier to fill the bottles without excessive foaming, and you retain the carbonation lost from mixing.
If you have to fill an already mixed beverage, it's doable, it's just messier. Fill your bottles in the sink, because they will foam over. Sometimes you have to fill as much as you can, and then let the foam dissipate a bit before filling the rest of the way. Fill the bottles gently, instead of having the tip of your filler all the way at the bottom, move it all the way to the top of the bottle and tilt it so the beverage runs down the side. Keep the temperature as low as possible, and turning the pressure down helps, too, as long as you turn it back up again if you're leaving some in the keg after bottling.
I'm going to have to make a video one of these days, because seeing it done helps out quite a lot.