There are a variety of ways to do this using the spices themselves.
One option is to steep the spices and use the steeping water as part of your water for the recipe.
Pros: Easy, heat sanitizes the spices, you can add a portion to the batch and taste then add more if you wish.
Cons: Heat will drive off some of the delicate flavors/aromas of the spices. Adds a step
Second option: Add the ground spices right to the recipe.
Pros: easy, retains all of the spice character
Cons: Spice character will take time to develop, so less control. Spice "sludge" in bottom of bottles/keg.
Third option: Make a tincture of the spices in a neutral spirit (grain alcohol, vodka) and add to the batch to taste.
Pros/cons similar to steeping except you have added alcohol (trivial) and cost/steps
Others may chime in with different suggestions. I am not sure I would pick any one of the three as a strong front runner. As a home brewer, I am a fan of adding freshly ground spices right to the batch, but you have to live with the results and tweak future batches. Also, I am not sure you would be able to taste the subtleties of using the best spices in the most careful way through the flavor hammer that is root beer.
Hope this helps.